Repository navigation
fix(hibernate5): an association block that is a branch of or keeps the entities without the association - #16931
borinquenkid wants to merge 7 commits into
Conversation
…ther branch matches Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…e entities without the association The criteria guide documents an association block inside or as one branch: accounts that have either performed transactions OR were recently created. The block was an inner join, so an account without transactions was dropped before the other branch could match it. A block that has no join type of its own, inside an or, is now a left join. Fixes #16924 Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Not approving. An association block that accepts a null now matches an entity that has no association. A later explicit inner join also reuses that left join.
…ociated entity A null test in the block matched the entities without the association, because the left join gives null for the missing one. The block now also requires the id of the joined alias. The shared block cases skip Neo4j until #16836 is merged. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
A null test in an association block no longer matches an entity that has no association. Thread PRRT_kwDOAAfRJ862Qfia resolved. Not approving. An empty association block no longer requires the association, and a later inner join reuses the left join.
…uires an associated entity, and an empty block does too A block outside an or that reuses the left join of a block in one no longer returns the entities without the association, and an empty block in an or keeps requiring an associated entity of the whole entity, as its inner join did.
jamesfredley
left a comment
There was a problem hiding this comment.
An empty association block requires the association again, and a later inner join no longer reuses the left join as if the child were optional. Threads PRRT_kwDOAAfRJ862VrVg and PRRT_kwDOAAfRJ862VrVl resolved. Not approving. A later block that asks for a left join is treated as if it required the child.
…r not an or joined the association with a left join
or { child {...}; eq(...) }; child(LEFT_JOIN) { isNull('name') } keeps the entity without a child, as the left join the
second block asked for does.
jamesfredley
left a comment
There was a problem hiding this comment.
A later block that asks for a left join keeps that left join. Not approving. A later block that asks for an inner join still reuses the left join.
| // a block that is a branch of an "or" asks for an associated entity, and so does a block that | ||
| // reuses the left join of one, as a block outside an "or" always did | ||
| // (a join type the caller named is kept as the caller named it) | ||
| final boolean requiresAssociated = branchOfOr || (!hasMoreThanOneArg && leftBlockAliases.contains(blockAlias)); |
There was a problem hiding this comment.
or { child { eq('name', 'kid') }; eq('name', 'orphan') }; child(CriteriaSpecification.INNER_JOIN) { isNull('name') }, where orphan has no child. The list returns orphan. The later block asked for an inner join. Require the child.
…and is no branch of an or CriteriaOrAssociationBlockSpec expects an association block without criteria to leave out the entities that have no associated entity, and to add no branch to the or it stands in, as on the datastores that join. The in-memory store matched nothing for the block and let the other branch of the or find the orphan. The block is now skipped as a branch and the whole result is restricted to the entities that have an associated entity. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
| // a block that is a branch of an "or" asks for an associated entity, and so does a block that | ||
| // reuses the left join of one, as a block outside an "or" always did | ||
| // (a join type the caller named is kept as the caller named it) | ||
| final boolean requiresAssociated = branchOfOr || (!hasMoreThanOneArg && leftBlockAliases.contains(blockAlias)); |
There was a problem hiding this comment.
with has a child named kid. orphan has no child. or { child { eq('name', 'kid') }; eq('name', 'orphan') } then child(INNER_JOIN) {} should return only with. It returns with and orphan. The second block reuses the left join from the or, and the extra argument turns off the existence check. Keep the inner join when the caller asks for one.
…d a block in an or of a detached criteria keeps its left join
child(INNER_JOIN) { } after an or reused the left join the or had made for the same association and, as it named a join
type, skipped the existence check, so an entity without the association stayed in the result; a block that names an
inner join asks for an associated entity now. The query path of a detached criteria had no rule for a block that is a
branch of an or at all, so an entity without the association dropped out of the or, an empty block did not ask for an
associated entity and a block after the or did not either; it makes a left join for such a block, checks for an
associated entity as criteria does, and does not count a negation as an or. CriteriaOrAssociationBlockSpec runs
each row through criteria and through a detached criteria, and has the explicit join type rows.
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley Fixed in the new commit. Your case. The same rule through the other entry point. I ran every row of that spec through a detached criteria as well, and four of the eight earlier rows failed there: the query path used by detached criteria had no rule for a block that is a branch of an The H5 module (705 tests), the in-memory store and |
…nd a path a block repeats keeps one join
getOrCreateAlias reused the join of any earlier block of the same name whenever the block came with an alias, which a
block of a detached criteria always does, so dam { sire { ... } } filtered on the join of the root sire block and
returned nothing, and a second dam.sire block asked Hibernate for the same association path twice and failed with
a duplicate association path. The join made for the very path of the block is reused now, and a join made for the
same name under another path is not. The pedigree shapes of CriteriaNestedShapesSpec are checked through a detached
criteria as well, with the repeated nested blocks; the blocks that are branches of an or stay on criteria until #16931.
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…d criteria The detached criteria path keeps a left join for a block that is a branch of an or since #16931 (merged into this branch), so the three shapes that were checked through criteria only are checked through both. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An explicit inner join after one or is kept. The same join inside a second or still lets an entity without the association through.
| } | ||
| else if (requiresAssociated) { | ||
| // a missing associated entity is a null that a null test in the block would match | ||
| logicalExpression.args.add(0, Restrictions.isNotNull(blockAlias + ".id")); |
There was a problem hiding this comment.
with has a child named kid. orphan has no child. An or that asks for the child, then a second or with child(0), should return only with. It returns with and orphan. The existence check sits inside the second or, so the name branch bypasses it. Keep that check on the whole query.
An association block inside
or { }is one branch of the disjunction. The criteria guide documents it that way: "all accounts that have either performed transactions in the last 10 days OR have been recently created in the last 10 days". The block was an inner join, so an account without transactions was dropped before the other branch could match it.A block with no join type of its own, inside an
or, is now a left join.createAliasis unchanged: the docs say it is an inner join unless a join type is given.Tests: new shared TCK specs
CriteriaOrAssociationSpec(instance,isNull,isNotNullinor: the same on every binding) andCriteriaOrAssociationBlockSpec(block and to-many block inor; MongoDB skipped, it has no association blocks). Full Hibernate 5 suite passes,codeStyleis clean.CriteriaOrAssociationBlockSpecalso runs on Neo4j and passes there with #16836, so merge #16836 first.Fixes #16924
Evidence and the doc passage: #16924 (comment)
https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL